<template>
  <div>
    <table class="table table-bordered">
      <tr>
        <td>项目名称</td>
        <td>{{ sdata.L_Name }}</td>
      </tr>
      <tr>
        <td>项目理财总金额</td>
        <td>{{ sdata.L_Money }}</td>
      </tr>
      <tr>
        <td>用户理财金额</td>
        <td>{{ sdata.UL_Money }}</td>
      </tr>
      <tr>
        <td>赎回金额</td>
        <td>
          <input type="text" v-model="USH_Money" />
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <input type="button" value="赎回" @click="add" />
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
let router = useRouter();
let route = useRoute();

let data: any = reactive({
  sdata: {},
  USH_Money: 0,
});
let { sdata, USH_Money } = toRefs(data);

onMounted(() => {
  Show();
});

const Show = () => {
  axios({
    url: 'http://localhost:63350/api/User/GetShuHuiXian',
    method: 'get',
    params: {
      L_Id: route.query.L_Id,
    },
  }).then((res) => {
    console.log(res);
    sdata.value = res.data.data[0];
  });
};

const add = () => {
  if (USH_Money.value > sdata.value.UL_Money) {
    alert('没有这么多钱');
    return;
  }
  axios({
    url: 'http://localhost:63350/api/User/PostShuhui',
    method: 'post',
    data: {
      L_Id: route.query.L_Id,
      USH_Money: USH_Money.value,
    },
  }).then((res) => {
    console.log(res);
    if (res.data.data > 0) {
      alert('赎回成功');
      router.push({
        path: '/show',
        query: {
          U_Id: route.query.U_Id,
        },
      });
    }
  });
};
</script>

<style scoped></style>
